package com.wutu.nbyjk8.controller;


import com.alibaba.fastjson.JSONObject;
import com.wutu.nbyjk8.service.impl.CarPassThroughRecordService;
import com.wutu.nbyjk8.vo.EntryData;
import com.wutu.nbyjk8.vo.ExitData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/receive/parking/api")
@Slf4j
public class ParkingController {

    @Autowired
    CarPassThroughRecordService carPassThroughRecordService;

    @PostMapping("/enter")
    public Object receiveEntry(@RequestBody EntryData entryData) {
        // 处理进场数据逻辑
        try {
            carPassThroughRecordService.receiveEntry(entryData);
        } catch (Exception e) {
            log.error("接收失败{}", e);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", 500);
            jsonObject.put("msg", "接收失败");
            return jsonObject;
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "接收成功");
        return jsonObject;
    }

    @PostMapping("/exit")
    public Object receiveExit(@RequestBody ExitData exitData) {
        // 处理出场数据逻辑
        try {
            carPassThroughRecordService.receiveExit(exitData);
        } catch (Exception e) {
            log.error("接收失败{}", e);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", 500);
            jsonObject.put("msg", "接收失败");
            return jsonObject;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "接收成功");
        return jsonObject;
    }
}

